/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import diagram.locations.AbsoluteLocation;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.TransferHandler;
import listeners.DragMouseAdapter;
import model.ToolbarModel;

/**
 *
 * @author Jelle
 */
public class ToolbarAction extends AbstractAction {

    private int modus;
    private ToolbarModel model;

    public ToolbarAction() {
    }

    public ToolbarAction(String s, AbsoluteLocation location, ToolbarModel model) {
        this.model =  model;
        if (s.equals("add")) {
            modus = 0;
        }
        else if (s.equals("clear")) {
            modus = 1;
        }

    }

    public void actionPerformed(ActionEvent e) {
        switch (modus) {
            case 0:
                System.out.println("ToolbarAction modus 0 (add)");
                ImageIcon ss = new ImageIcon("C:\\Users\\Jelle\\Documents\\III\\Eindwerk\\icons\\HP-Explorer-Blue-Dock-512.png");
                JButton b = new JButton(ss);
                ss.setDescription("a");
                MouseListener listener = new DragMouseAdapter();
                b.addMouseListener(listener);
                b.setTransferHandler(new TransferHandler("icon"));
                model.addItem(b);
                System.out.println(model.getItems().size());
                break;
            case 1:
                System.out.println("ToolbarAction modus 1 (add)");
                model.clearModel();
                break;
        }
    }
}
